<!-- 首页 -->
<template>
  <div class="rabbit">
    <template>
      <div class="block container">
        <h1 class="bg">

          <div class="top">
            <!-- 全部分类 -->
            <ul class="list">
              <li v-for="(item, index) in msgs" :key="index">
                <router-link :to="'/home/category?id=' + item.id" tag="span">{{
                item.name
                }}</router-link>
                <span v-for="(item, index) in item.children.slice(0, 2)" :key="index">
                  <router-link :to="'/home/subs?id=' + item.id" tag="span">{{
                  item.name
                  }}</router-link>
                </span>
                <div class="listRt">
                  <h4>
                    <span>分类推荐</span><span>根据您的购买或浏览记录推荐</span>
                  </h4>
                  <ul>
                    <router-link to="" tag="li" class="listRt-li" v-for="(item, index) in item.goods" :key="index">
                      <router-link to="" tag="a" href="javascript:;">
                        <img :src="item.picture" alt="">
                        <div>
                          <p>{{ item.name }}</p>
                          <p class="p1">{{ item.desc }}</p>
                          <p>￥{{ item.price }}</p>
                        </div>
                      </router-link>
                    </router-link>
                  </ul>
                </div>
              </li>
              <router-link to="" tag="li">
                <router-link to="/home/category" tag="span">品牌</router-link>
                <span>
                  <router-link to="/home/subs" tag="span">品牌推荐</router-link>
                </span>
                <div class="listRt">
                  <h4>
                    <span>品牌推荐</span><span>根据您的购买或浏览记录推荐</span>
                  </h4>
                  <ul>
                    <router-link to="" tag="li" class="ppLi" v-for="(item, index) in ppImg.slice(0,6)" :key="index">
                      <router-link to="" tag="a" href="javascript:;">
                        <img :src="item.picture" alt="">
                        <div>
                          <p style="color:#999;margin-top: 8px;font-size: 14px;">{{ item.place }}</p>
                          <p style="color:#666;margin-top: 8px;">{{ item.name }}</p>
                          <p style="color:#999;margin-top: 8px;font-size: 14px;">{{ item.desc }}</p>
                        </div>
                      </router-link>
                    </router-link>
                  </ul>
                </div>
              </router-link>
            </ul>
            <!-- 轮播图 -->
            <el-carousel trigger="click" height="500px">
              <el-carousel-item v-for="(item, index) in img" :key="index">
                <img :src="item.imgUrl" alt="" />
              </el-carousel-item>
            </el-carousel>
          </div>
        </h1>
        <!-- 新鲜好物 -->
        <div class="content">
          <div class="content-top">
            <h3 class="head">
              <span>新鲜的好物</span>
              <span>新鲜出炉 质量可靠</span>
            </h3>
            <a href="javascript:;">查看全部></a>
          </div>
          <div class="box">
            <ul>
              <li v-for="(item, index) in xxHw" :key="index">
                <router-link tag="a" :to="'/home/Details?id='+item.id" href="javascript:;">
                  <img :src="item.picture" alt="">
                  <p>{{ item.name }}</p>
                  <p>￥{{ item.price }}</p>
                </router-link>
              </li>
            </ul>
          </div>
        </div>
        <!-- 人气推荐 -->
        <div class="content1">
          <div class="content-top1">
            <h3 class="head1">
              <span>人气推荐</span>
              <span>人气爆款，不容错过</span>
            </h3>
          </div>
          <div class="box1">
            <ul>
              <li v-for="(item, index) in rq" :key="index">
                <router-link tag="a" :to="'/home/Details?id='+item.id" href="javascript:;">
                  <img :src="item.picture" alt="">
                  <p>{{ item.title }}</p>
                  <p>{{ item.alt }}</p>
                </router-link>
              </li>
            </ul>
          </div>
        </div>
        <!-- 热门品牌 -->
        <div class="content2">
          <div class="content2-item">
            <div class="head2">
              <h3>
                <span>热门品牌</span>
                <span>国际经典 品质保证</span>
              </h3>
              <a href="javascript:;">
                <i class="el-icon-arrow-left" @click="fast"></i>
              </a>
              <a href="javascript:;" @click="last">
                <i class="el-icon-arrow-right"></i>
              </a>
            </div>
            <div class="box2">
              <ul ref="ul">
                <li v-for="(item, index) in ppImg" :key="index">
                  <router-link tag="a" to="" href="javascript:;">
                    <img :src="ppImg[index].logo" alt="">
                  </router-link>
                </li>
              </ul>
            </div>
          </div>
        </div>
        <!-- 商品内容 -->
        <div class="content3">
          <div class="content3-item" v-for="(item,index) in goods" :key="index">
            <div class="head3">
              <h3>{{item.name}}</h3>
              <div class="sub">
                <router-link v-for="(item,index) in item.children" :key="index" :to="'/home/subs?id='+item.id" tag="a">
                  {{item.name}}
                </router-link>
              </div>
              <router-link :to="'/home/category?id='+item.id" tag="a">
                查看全部<i class="el-icon-arrow-right"></i>
              </router-link>
            </div>
            <div class="box3">
              <router-link to="" tag="a">
                <img :src="item.picture" alt="">
                <div>
                  <span>居家馆</span>
                  <span>全场3件8折</span>
                </div>
              </router-link>
              <ul>
                <li v-for="(item,index) in item.goods" :key="index">
                  <div>
                    <router-link :to="'/home/Details?id='+item.id" tag="a">
                      <img :src="item.picture" alt="">
                    </router-link>
                    <p>{{item.name}}</p>
                    <p>{{item.desc}}</p>
                    <p>￥{{item.price}}</p>
                    <div class="extra">
                      <router-link tag="a" to="">
                        <span>找相似</span>
                        <span>发现现多宝贝></span>
                      </router-link>
                    </div>
                  </div>
                </li>

              </ul>
            </div>
          </div>
        </div>
        <!-- 最新专题 -->
        <div class="content4">
          <div class="content4-item">
            <div class="head4">
              <h3>最新专题</h3>
              <router-link to="" tag="a">
                查看全部<i class="el-icon-arrow-right"></i>
              </router-link>
            </div>
            <div class="box4">
              <div v-for="(item,index) in special" :key="index">
                <router-link to="" tag="a">
                  <img :src="item.cover" alt="">
                  <div class="meta">
                    <p>
                      <span>{{item.title}}</span>
                      <span>{{item.summary}}</span>
                    </p>
                    <span>¥{{item.lowestPrice}}起</span>
                  </div>
                  <div class="foot">
                    <span><i class="iconfont">&#xe86f;</i>{{item.collectNum}}</span>
                    <span><i class="el-icon-view"></i>{{item.viewNum}}</span>
                    <span><i class="el-icon-document"></i>{{item.replyNum}}</span>
                  </div>
                </router-link>
              </div>
            </div>
          </div>
        </div>
      </div>
    </template>
  </div>
</template>
  

<script>
export default {
  name: "rabbit",
  data() {
    return {
      //轮播图
      img: [],
      //二级菜单列表

      msgs: [],
      //二级菜单展示页
      imgUrl: [],
      //品牌展示页
      ppImg: [],
      //新鲜好物
      xxHw: [],
      //人气
      rq: [],
      //商品内容
      goods: [],
      //最新专题
      special: []
    };
  },
  components: {},
  mounted() {
    //获取轮播图
    this.$axios.get("/home/banner").then((res) => {
      res.data.result.forEach((arr) => {
        this.img.push(arr);
      });
    });
    //二级菜单
    this.$axios.get("/home/category/head").then((res) => {
      this.msgs = res.data.result
    });
    //品牌推荐
    this.$axios.get("/home/brand").then((res) => {
      res.data.result.forEach((arr) => {
        this.ppImg.push(arr)
      })
    });
    //新鲜好物
    this.$axios.get("/home/new").then((res) => {
      res.data.result.forEach((arr) => {
        this.xxHw.push(arr)
      })
    });
    //人气
    this.$axios.get("/home/hot").then((res) => {
      res.data.result.forEach((arr) => {
        this.rq.push(arr)
      })
    });
    //商品内容
    this.$axios.get("/home/goods").then((res) => {
      res.data.result.forEach((arr) => {
        this.goods.push(arr)
      })
      console.log(this.goods);
    });
    //最新专题
    this.$axios.get("/home/special").then((res) => {
      this.special = res.data.result
      console.log(this.special);
    })
  },
  methods: {
    last() {
      let ul = this.$refs.ul
      ul.style.transform = "translateX(-50%)"
    },
    fast() {
      let ul = this.$refs.ul
      ul.style.transform = "translateX(0%)"
    }
  },
};
</script>
<style lang="less" scoped>
.rabbit {
  position: relative;
  background: #fff;
}

.bg {
  width: 1980px;
  padding-left:370px;
  margin-left: -370px;
  background-color: #f5f5f5;
}

.list {
  position: absolute;
  top: 0;
  width: 250px;
  height: 500px;
  background-color: rgba(0, 0, 0, .8);
  z-index: 99;
}

.list&>li {
  padding-left: 40px;
  height: 50px;
  line-height: 50px;
  color: #fff;

  &>span:first-child {
    font-size: 16px;
  }

  &>span {

    margin-right: 4px;
    font-size: 14px;
    cursor: pointer;
  }

  &:hover .listRt {
    display: block;
  }
}


//全部分类展示页
.list&>li:hover {
  background-color: #27ba9b;
}

.listRt {
  color: #333;
  width: 960px;
  height: 500px;
  background: hsla(0, 0%, 100%, 0.8);
  position: absolute;
  left: 250px;
  top: 0;
  display: none;
  padding: 0 15px;
  z-index: 999;
  overflow: hidden;

  .ppLi {
    height: 180px;

    img {
      width: 120px;
      height: 160px;
    }
  }

  h4 {
    font-size: 20px;
    font-weight: 400;
    line-height: 80px;

    span:last-child {
      color: #666;
      font-size: 16px;
      margin-left: 5px;
    }
  }

  ul {
    width: 1000px;
    display: flex;
    flex-wrap: wrap;

    li {
      width: 310px;
      height: 120px;
      margin-right: 15px;
      margin-bottom: 15px;
      border: 1px solid #eee;
      border-radius: 4px;
      background: #fff;
      padding-left: 0;

      a {
        display: flex;
        width: 100%;
        height: 100%;
        padding: 10px;

        img {
          width: 95px;
          height: 95px;
          margin-bottom: 25px;
        }

        &>div {
          padding-left: 10px;
          line-height: 24px;
          width: 190px;
          color: #000;

          p:last-child {
            font-size: 20px;
            color: red;
          }

          .p1 {
            font-size: 14px;
            color: #999;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
          }
        }
      }
    }
  }
}

//新鲜好物头部
.content-top {
  display: flex;
  background-color: #fff;
  justify-content: space-between;
  align-items: center;

  a {
    color: #999;
  }

  a:hover {
    color: #27ba9b;
  }

  .head {
    padding: 40px 0;
    display: flex;
    align-items: flex-end;

    span:first-child {
      font-size: 32px;
      font-weight: 400;
      margin-left: 6px;
      height: 35px;
      line-height: 35px;
    }

    span:last-child {
      font-size: 16px;
      color: #999;
      margin-left: 20px;
    }
  }
}

//新鲜好物内容
.box {
  position: relative;
  height: 426px;

  ul {
    display: flex;
    justify-content: space-between;
    height: 406px;

    li {
      width: 306px;
      height: 406px;
      background: #f0f9f4;
      transition: all .5s;

      img {
        max-width: 100%;
        max-height: 100%;
        vertical-align: middle;
      }

      p {
        font-size: 22px;
        padding: 12px 30px 0 30px;
        text-align: center;
        color: #000;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
      }

      p:last-child {
        color: #cf4444;
        margin-top: 10px;
        ;
      }
    }

    li:hover {
      box-shadow: 0px 5px 5px 0px #ccc;
      margin-top: -5px;
    }
  }
}

//人气头部
.content-top1 {
  display: flex;
  background-color: #fff;
  justify-content: space-between;
  align-items: center;

  a {
    color: #999;
  }

  a:hover {
    color: #27ba9b;
  }

  .head1 {
    padding: 40px 0;
    display: flex;
    align-items: flex-end;

    span:first-child {
      font-size: 32px;
      font-weight: 400;
      margin-left: 6px;
      height: 35px;
      line-height: 35px;
    }

    span:last-child {
      font-size: 16px;
      color: #999;
      margin-left: 20px;
    }
  }
}

//人气身体
.box1 {
  position: relative;

  ul {
    display: flex;
    justify-content: space-between;
    height: 406px;

    li {
      width: 306px;
      height: 406px;
      background: #fff;
      transition: all .5s;

      img {
        max-width: 100%;
        max-height: 100%;
        vertical-align: middle;
      }

      p {
        font-size: 22px;
        padding: 12px 30px 0 30px;
        text-align: center;
        color: #000;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
      }

      p:last-child {
        color: #999;
        font-size: 18px;
        margin-top: 10px;
      }
    }

    li:hover {
      box-shadow: 0px 5px 5px 0px #ccc;
      margin-top: -5px;
    }
  }
}

//热门品牌
.content2 {
  width: 1980px;
  margin-left: -370px;
  background-color: #f5f5f5;

  .content2-item {
    width: 1240px;
    margin: 0 auto;
    position: relative;

    .head2 {
      padding: 40px 0;
      display: flex;
      align-items: flex-end;
      background: #f5f5f5;

      h3 {
        flex: 1;
        font-size: 32px;
        font-weight: 400;
        margin-left: 6px;
        height: 35px;
        line-height: 35px;

        i {
          width: 20px;
          height: 20px;
          background: #ccc;
          color: #fff;
          display: inline-block;
          text-align: center;
          margin-left: 5px;
          background: #27ba9b;
        }

        span:last-child {
          font-size: 16px;
          color: #999;
          margin-left: 20px;
        }
      }

      a {
        width: 20px;
        height: 20px;
        background: #ccc;
        color: #fff;
        display: inline-block;
        text-align: center;
        margin-left: 5px;
        background: #27ba9b;
        // cursor: not-allowed;
      }
    }

    .box2 {
      display: flex;
      width: 100%;
      height: 345px;
      overflow: hidden;
      background: #f5f5f5;

      ul {
        width: 200%;
        display: flex;
        transition: all 1s;

        li {
          margin-right: 10px;
          width: 240px;

          img {
            width: 240px;
            height: 305px
          }
        }
      }
    }
  }
}

//商品内容
.content3-item {
  width: 1240px;
  margin: 0 auto;
  position: relative;

  &>.head3 {
    padding: 40px 0;
    display: flex;
    align-items: flex-end;

    &>h3 {
      flex: 1;
      font-size: 32px;
      font-weight: 400;
      margin-left: 6px;
      height: 35px;
      line-height: 35px;
    }

    &>div {
      margin-right: 80px;
      margin-top: 2px;

      &>a {
        padding: 5px 12px;
        font-size: 16px;
        border-radius: 4px;
        color: #333;
      }

      &>a:hover {
        color: #fff;
        background-color: #27ba9b;
      }
    }

    &>a {
      font-size: 16px;
      vertical-align: middle;
      margin-right: 4px;
      color: #999;

      &>i {
        font-size: 14px;
        vertical-align: middle;
        position: relative;
        // top: 2px;
        color: #ccc;
      }
    }

    &>a:hover {
      color: #27ba9b;
    }
  }

  &>.box3 {
    display: flex;

    &>a {
      width: 240px;
      height: 610px;
      margin-right: 10px;
      position: relative;

      &>img {
        width: 100%;
        height: 100%;
        object-fit: cover;
      }

      &>div {
        width: 188px;
        height: 66px;
        display: flex;
        font-size: 18px;
        color: #fff;
        line-height: 66px;
        font-weight: 400;
        position: absolute;
        left: 0;
        top: 50%;
        transform: translate3d(0, -50%, 0);

        &>span:first-child {
          width: 76px;
          background: rgba(0, 0, 0, .9);
          padding-left: 5px;
        }

        &>span:last-child {
          flex: 1;
          background: rgba(0, 0, 0, .7);
          padding-left: 5px;

        }
      }
    }

    &>ul {
      width: 1050px;
      display: flex;
      flex-wrap: wrap;

      &>li {
        width: 240px;
        height: 300px;
        margin-right: 10px;
        margin-bottom: 10px;

        &>div:hover {
          border: 1px solid #27ba9b;
        }

        &>div:hover .extra {
          transform: translate3d(0, 0%, 0);
        }

        &>div {
          border-color: #27ba9b;
          height: 300px;
          padding: 0px 30px;
          position: relative;
          overflow: hidden;
          border: 1px solid transparent;
          transition: all .5s;

          &>a {
            display: block;
            width: 160px;
            height: 160px;
            margin: 0 auto;

            &>img {
              width: 100%;
              height: 100%;
            }
          }

          &>p {
            margin-top: 6px;
            font-size: 16px;
          }

          &>p:first-child {
            height: 44px;
          }

          &>p:nth-child(3) {
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            color: #666;
            height: 22px;
            margin-top: 8px;
          }

          &>p:nth-child(4) {
            margin-top: 10px;
            font-size: 20px;
            color: #cf4444;
          }

          &>.extra {
            position: absolute;
            left: 0;
            bottom: 0;
            height: 86px;
            width: 100%;
            background: #27ba9b;
            text-align: center;
            transform: translate3d(0, 100%, 0);
            transition: all .5s;

            span {
              display: block;
              color: #fff;
              width: 120px;
              margin: 0 auto;
            }

            span:first-child {
              font-size: 18px;
              border-bottom: 1px solid #fff;
              line-height: 40px;
              margin-top: 5px;

            }

            span:last-child {
              margin-top: 5px;
              font-size: 14px;
            }
          }
        }
      }

    }
  }
}

//最新专题
.content4 {
  width: 1980px;
  margin-left: -370px;
  background-color: #f5f5f5;

  .content4-item {
    width: 1240px;
    margin: 0 auto;
    position: relative;

    &>.head4 {
      padding: 40px 0;
      display: flex;
      align-items: flex-end;

      &>h3 {
        flex: 1;
        font-size: 32px;
        font-weight: 400;
        margin-left: 6px;
        height: 35px;
        line-height: 35px;
      }

      &>a {
        font-size: 16px;
        vertical-align: middle;
        margin-right: 4px;
        color: #999;
      }

      &>a:hover {
        color: #27ba9b;
      }

      &>span {
        font-size: 16px;
        vertical-align: middle;
        margin-right: 4px;
        color: #999;
      }
    }

    &>.box4 {
      height: 380px;
      padding-bottom: 20px;
      display: flex;
      justify-content: space-between;

      &>div {
        width: 404px;
        background: #fff;
        transition: all .5s;

        &>a {
          display: block;
          width: 100%;
          height: 288px;
          position: relative;

          &>img {
            width: 100%;
            height: 100%;
            object-fit: cover;
          }

          &>.meta {
            background-image: linear-gradient(0deg, rgba(0, 0, 0, .8), transparent 50%);
            position: absolute;
            left: 0;
            top: 0;
            width: 100%;
            height: 288px;

            &>p {
              position: absolute;
              bottom: 0;
              left: 0;
              padding-left: 16px;
              width: 70%;
              height: 70px;

              &>span:first-child {
                color: #fff;
                font-size: 22px;
                display: block;
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
              }

              &>span:last-child {
                display: block;
                font-size: 19px;
                color: #999;
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
              }
            }

            &>span {
              position: absolute;
              bottom: 25px;
              right: 16px;
              line-height: 1;
              padding: 4px 8px 4px 7px;
              color: #cf4444;
              font-size: 17px;
              background-color: #fff;
              border-radius: 2px;
            }
          }

          &>.foot {
            height: 72px;
            line-height: 72px;
            padding: 0 20px;
            font-size: 16px;

            &>span {
              float: left;
              margin-right: 25px;
              vertical-align: middle;
              font-size: 16px;
              color: #000;

              &>i {
                margin-right: 5px;
              }
            }

            &>span:last-child {
              float: right;
            }
          }
        }
      }

      &>div:hover {
        box-shadow: 0px 5px 5px 0px #ccc;
        margin-top: -5px;
      }
    }
  }
}
</style>
<style>
.rabbit .el-carousel__item h3 {
  color: #475669;
  font-size: 14px;
  opacity: 0.75;
  line-height: 150px;
  margin: 0;
}

.rabbit .el-carousel__item:nth-child(2n) {
  background-color: #f5f5f5;
}


.rabbit .el-carousel__item:nth-child(2n+1) {
  background-color:#f5f5f5;
}

.rabbit .el-carousel__button {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background-color: #fff;
  margin: 3px;
}

.rabbit .el-carousel__indicators--horizontal {
  left: 38%;
  bottom: 15px;
}

.rabbit .el-carousel__arrow--left {
  left: 14%;
}
.rabbit .el-carousel__arrow--right{
  right:39%;
}
.rabbit .el-carousel__arrow {
  width: 50px;
  height: 50px;
  font-size: 18px;
  background-color: rgba(77, 76, 76, 0.5);
}
</style>